package com.bootcamp.sb1126yml.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @program: spring-boot
 * @description:
 * @author: Keyu Li
 * @create: 2021-11-26 11:08
 **/

/*
* prefix + 成员变量名 -> 用 set方法给成员变量赋值
* */

@Data
@Configuration
@ConfigurationProperties(prefix = "b.datasource")
public class DataSourceConfiguration2 {
    String url;
    String username;
    String password;

    @Bean("dataSource2")
    public DataSource dataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
